package com.leyou.item.controller;


import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entitiy.TbSpecParam;
import com.leyou.item.service.TbSpecParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 规格参数组下的参数名 前端控制器
 * </p>
 *
 * @author HM
 * @since 2021-06-16
 */
@Controller
@RequestMapping("/spec")
public class TbSpecParamController {
    @Autowired
    private TbSpecParamService specService;

    /**
     * 查询 规格参数信息
     * @param gid  分组id
     * @return
     */
    @GetMapping("/params")
    public ResponseEntity<List<SpecParamDTO>> findSpecParam(
            @RequestParam(name = "gid",required = false) Long gid,
            @RequestParam(name = "cid",required = false) Long cid){
        List<SpecParamDTO> specParamDTOList = specService.findSpecParam(gid,cid);
        return ResponseEntity.ok(specParamDTOList);
    }

    @PostMapping("/param")
    public ResponseEntity<Void> add(@RequestBody TbSpecParam tbSpecParam){
        specService.add(tbSpecParam);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }
}

